package com.smfx.yxt.view;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.smfx.yxt.common.Const;
import com.smfx.yxt.model.OrganizeDepart;
import com.smfx.yxt.model.OrganizeGroup;
import com.smfx.yxt.wechat.utils.WechatGlobalMap;

public class OrganizeGroupView extends OrganizeGroup {

	private static final long serialVersionUID = 9194633094307588247L;

	@SuppressWarnings("unchecked")
	public String getPositionText() {
		if(StringUtils.isNotBlank(super.getIds())) {
			String groupCode = super.getGroupCode();
			if(StringUtils.isNotBlank(groupCode)) {
				if(groupCode.equals("SUBJECT_GROUP")) {
					Map<Integer, String> subjectMap = (Map<Integer, String>) WechatGlobalMap.get(Const.CACHE_SUBJECT).getValue();
					String[] strings = super.getIds().split(",");
					String value = "";
					for(int i = 0; i < strings.length; i++) {
						value += subjectMap.get(Integer.valueOf(strings[i]));
						if((i+1) != strings.length) value += ",";
					}
					return value;
				}else if(groupCode.equals("GRADE_GROUP")) {
					Map<Integer, String> gradeMap = (Map<Integer, String>) WechatGlobalMap.get(Const.CACHE_GRADE).getValue();
					String[] strings = super.getIds().split(",");
					String value = "";
					for(int i = 0; i < strings.length; i++) {
						value += gradeMap.get(Integer.valueOf(strings[i]));
						if((i+1) != strings.length) value += ",";
					}
					return value;
				}
			}
			Map<String, OrganizeDepart> map = (Map<String, OrganizeDepart>) WechatGlobalMap.get(Const.CACHE_ORGANIZE_DEPART).getValue();
			String[] strings = super.getIds().split(",");
			String value = "";
			for(int i = 0; i < strings.length; i++) {
				if(map.get(strings[i]) != null) {
					value += map.get(strings[i]).getPosition();
					if((i+1) != strings.length) value += ",";
				}
			}
			return value;
		}
		return "";
	}
}
